<?php

namespace App\Http\Controllers\Admin;

use App\Http\Query\CategoryQuery;
use app\Model\Base;
use app\Model\OrderModel;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Log;
use function MongoDB\BSON\toJSON;
use SplFileObject;

class JapanStorehouseController extends Controller

{

    function show_storehouse(Request $request)
    {

        $getParam = $request->all();
        $map = [];
        if (!empty($getParam['storehouse_id'])) {
            $map['sm.storehouse_id'] = $getParam['storehouse_id'];
        }
        if (!empty($getParam['category_id'])) {
            $map['cm.category_id'] = $getParam['category_id'];
        }
        if (!empty($getParam['goods_id'])) {
            $map['gm.goods_id'] = $getParam['goods_id'];
        }
//        $map['gm.state'] = $request->input('state', 1);

        if (!empty($getParam['state'])) {
            if ($getParam['state'] == '1') {
                $map['gm.state'] = '2';
            } else {
                $map['gm.state'] = '1';
            }
        }
        if (!empty($getParam['bad_num'])) {
            $map[] = array('sdz.bad_num', '<>', '0');
        }

        $list = DB::table('storehouse_detailed_size as sdz')
            ->select(DB::raw('sm.storehouse_name,cm.category_name,gm.goods_name,gm.goods_id,gm.goods_code,sdz.color,sdz.size,sdz.bad_num,date_format(gm.stop_sales, \'%Y-%m-%d\') AS stop_sales,date_format(now(), \'%Y-%m-%d\') AS date_time,sdz.web_num,sdz.num'))
            ->leftJoin('storehouse_master as sm', 'sm.storehouse_id', '=', 'sdz.storehouse_id')
            ->leftJoin('goods_master as gm', 'sdz.goods_id', '=', 'gm.goods_id')
            ->leftJoin('category_master as cm', 'gm.category_id', '=', 'cm.category_id')
            ->where($map)
            ->get();
//                dump($list);
//                dump($getParam);
        $mo = new \App\Model\Base();
        return view('warehouse.show_storehouse', array(
            'storehouse' => $mo::storehouse(),
            'category' => $mo::category(),
            'goods' => $mo::goods(),
            'list' => $list,
            'param' => $getParam,
        )); // 返回视图
    }
}
